package org.itzheng.yuezhi.real.main;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.itzheng.utils.common.ActivityAnimUtil;
import org.itzheng.yuezhi.R;
import org.itzheng.yuezhi.adapter.CommonMenuInfoRcvAdapter;
import org.itzheng.yuezhi.base.BaseFragment;
import org.itzheng.yuezhi.entity.MenuInfo;
import org.itzheng.yuezhi.real.tools.bluetooth.BluetoothActivity;
import org.itzheng.yuezhi.real.tools.login.ThirdPartyLoginActivity;
import org.itzheng.yuezhi.utils.comm.UIUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by admin on 2017/7/20.
 */

public class ToolsFragment extends BaseFragment {
    View rootView;
    @BindView(R.id.rcvContent)
    RecyclerView rcvContent;
    Unbinder unbinder;

    @Override
    protected View onCreateView(LayoutInflater inflater, ViewGroup container) {
        if (rootView == null) {
            rootView = UIUtils.inflate(R.layout.fragment_main_tools);
            unbinder = ButterKnife.bind(this, rootView);
            setAdapter();
        }
        return rootView;
    }

    CommonMenuInfoRcvAdapter adapter;

    private void setAdapter() {
        if (adapter == null) {
            rcvContent.setLayoutManager(new LinearLayoutManager(UIUtils.getContext()));
            rcvContent.setAdapter(new CommonMenuInfoRcvAdapter(getMenuList()));
        } else {
            adapter.notifyDataSetChanged();
        }
    }

    public List<MenuInfo> getMenuList() {
        List<MenuInfo> menuInfos = new ArrayList<>();
        MenuInfo login = new MenuInfo();
        login.title = "登录";
        login.onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                UIUtils.startActivity(ThirdPartyLoginActivity.class);
//                getActivity().overridePendingTransition(R.anim.pull_bottom_in, R.anim.pull_bottom_out);
                ActivityAnimUtil.startActivityBottomInBottomOut(getActivity(), ThirdPartyLoginActivity.class);
//                ActivityAnimUtil.startActivity(getActivity(), ThirdPartyLoginActivity.class, R.anim.push_right_in, R.anim.push_right_out,
//                        R.anim.pull_right_in, R.anim.pull_right_out);
            }
        };
        menuInfos.add(login);

        //
        MenuInfo googleMap = new MenuInfo();
        googleMap.title = "Google地图";
        menuInfos.add(googleMap);
        //
        MenuInfo bluetooth = new MenuInfo();
        bluetooth.title = "蓝牙传输";
        bluetooth.onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ActivityAnimUtil.startActivityBottomInBottomOut(getActivity(), BluetoothActivity.class);
            }
        };
        menuInfos.add(bluetooth);
        return menuInfos;

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
